package br.com.lambdacore.persistence.dao.helper;

import java.lang.reflect.ParameterizedType;

public class PersistentClassDiscovery<T> {

	private Object object;

	private Class<T> persistentClass;

	public PersistentClassDiscovery(Object object) {
		this.object = object;
		configurePersistentClass();
	}

	public Class<T> getPersistentClass() {
		return persistentClass;
	}

	public static <T> PersistentClassDiscovery newInstance(Object object) {
		return new PersistentClassDiscovery(object);
	}

	@SuppressWarnings({"unchecked"})
	private void configurePersistentClass() {
		persistentClass = (Class<T>) ((ParameterizedType) object.getClass().getGenericSuperclass()).getActualTypeArguments()[0];
	}

}
